layui.use('form', function(){
  const form = layui.form;
  form.on('submit(formDemo)', function(data){
    $.ajax({
      type: 'POST',
      url: 'https://api.yizhanketang.cn/api/v1/todos',
      data: data.field,
      success(res) {
        console.log(res)
        location.reload()
      },
      error(e) {
        layer.msg('不能缺少content字段');
      }
    })

    return false;
  });

});



$(function() {

    $.ajax({
      method: 'GET',
      url: 'https://api.yizhanketang.cn/api/v1/todos',
      success(res) {
        console.log(res)
        const { data } = res
        data.forEach(item => {

          const {completed, content ,objectId} = item
          console.log(objectId)
          $(`<div class="item">
          <input type="checkbox" ${ completed ? 'checked' : '' }>
          <a href="todo.html?id=${objectId}"> ${ content }</a>
        </div>`).appendTo('.list')
        })

      }
    })

})
